<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增优惠券')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-onlineCoupon-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label">优惠券名称：</label>
                <div class="col-sm-8">
                    <input name="couponName" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">使用条件：</label>
                <div class="col-sm-2" style="display: flex;align-items: center">
                    <span style="font-size: 20px;margin-right: 10px">>=</span>
                    <input name="useCondition" class="form-control" type="text" onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">抵扣价格：</label>
                <div class="col-sm-8">
                    <input name="reduceMoney" class="form-control" type="text" onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">开始时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="startTime" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">到期时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="endTime" class="form-control" placeholder="yyyy-MM-dd" type="text" required >
                    </div>
                </div>
            </div>

            <div class="form-group">    
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <input name="remarks" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script type="text/javascript">
        var prefix = ctx + "onlineCoupon/onlineCoupon"
        $("#form-onlineCoupon-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
               var useCondition= $("input[name='useCondition']").val()
               var reduceMoney= $("input[name='reduceMoney']").val()
                if(parseFloat(useCondition) < parseFloat(reduceMoney)){
                    $.modal.alertError("抵扣价格高于使用价格")
                    return false;
                }
                $.operate.save(prefix + "/add", $('#form-onlineCoupon-add').serialize());
            }
        }

        $("input[name='startTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='endTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
    </script>
</body>
</html>